package BVRClient;

import BVRNetworking.BVRN_Definitions;
import BVRNetworking.BVRN_Packet;

public class BVRC_PacketGenerator
{
	/**
	 * 
	 * @return a connection header packet
	 */
	public static BVRN_Packet connectHeader()
	{
		BVRN_Packet packet = new BVRN_Packet(BVRN_Definitions.BVRN_HEADER_CONNECT);
		
		return packet;
	}
	
	/**
	 * 
	 * @param name
	 * @return a login packet
	 */
	public static BVRN_Packet loginHeader(String name)
	{
		BVRN_Packet packet = new BVRN_Packet();
		
		packet.setType(BVRN_Definitions.BVRN_LOGIN);
		
		packet.addParameter(name);
		
		return packet;
	}
	
	/**
	 * 
	 * @param name
	 * @return a packet to change the player's name
	 */
	public static BVRN_Packet nameSet(String name)
	{
		BVRN_Packet packet = new BVRN_Packet(BVRN_Definitions.BVRN_PLAYER_NAMESET);
		
		packet.addParameter(name);
		
		return packet;
	}
	
	/**
	 * 
	 * @param angle
	 * @return a packet to change the player's rotation
	 */
	public static BVRN_Packet playerRotation(float angle)
	{
		BVRN_Packet packet = new BVRN_Packet(BVRN_Definitions.BVRN_PLAYER_ROTATION);
		
		packet.addParameter(angle);
		
		return packet;
	}
	
	/**
	 * 
	 * @param player
	 * @return a packet to update the server with the player's new velocity
	 */
	public static BVRN_Packet playerVelocity(BVRC_Player player)
	{
		BVRN_Packet packet = new BVRN_Packet();
		
		if (player == null)
			return packet;
		
		packet.setType(BVRN_Definitions.BVRN_SET_PLAYER_VELOCITY);
		packet.addParameter(player.getMovementSpeedX());
		packet.addParameter(player.getMovementSpeedY());
		
		return packet;
	}
	
	/**
	 * 
	 * @param player
	 * @return a packet to update the server with the player's new velocity
	 */
	public static BVRN_Packet playerPosition(BVRC_Player player)
	{
		BVRN_Packet packet = new BVRN_Packet();
		
		if (player == null)
			return packet;
		
		packet.setType(BVRN_Definitions.BVRN_SET_PLAYER_POSITION);
		packet.addParameter(player.getPosition().x);
		packet.addParameter(player.getPosition().y);
		
		return packet;
	}
	
	/**
	 * 
	 * @param projectile
	 * @return a packet to create a projectile
	 */
	public static BVRN_Packet createProjectile(BVRC_Projectile projectile)
	{
		BVRN_Packet packet = new BVRN_Packet();
		
		if (projectile == null)
			return packet;
		
		packet.setType(BVRN_Definitions.BVRN_CREATE_PROJECTILE);
		packet.addParameter(projectile.getPosition().x);
		packet.addParameter(projectile.getPosition().y);
		packet.addParameter(projectile.getRotation());
		packet.addParameter(projectile.getTeam().toString());
		packet.addParameter(projectile.getOwnerId());
		
		return packet;
	}
	
	/**
	 * 
	 * @return a player death packet
	 */
	public static BVRN_Packet playerDeath()
	{
		BVRN_Packet packet = new BVRN_Packet(BVRN_Definitions.BVRN_PLAYER_DEATH);
		
		return packet;
	}
}